package me.j360.springboot.simple.bean.search.result;

import me.j360.springboot.simple.bean.search.Search;
import org.springframework.util.Assert;

import java.util.List;

/**
 * 说明：
 * Bean类 - 返回结果 - 列表
 *
 * ============================================================================
 * 版权所有 2015 qiushihua。
 *
 * @author qiushihua
 * @version 0.1 2015-08-03
 * ============================================================================
 */
public class ResultList extends Result {

    private final Integer totalCount;
    private final Integer pageCount;
    private final List<?> list;

    public Integer getTotalCount() {
        return totalCount;
    }

    public Integer getPageCount() {
        return pageCount;
    }

    public List<?> getList() {
        return list;
    }

    private ResultList(Search search, Integer totalCount, Integer pageCount, List<?> list) {
        super(search);
        this.totalCount = totalCount;
        this.pageCount = pageCount;
        this.list = list;
    }

    private static Builder newBuilder() {
        return new Builder();
    }

    public static ResultList list(Search search, Integer totalCount, Integer pageCount, List<?> list) {
        return newBuilder().setSearch(search).setTotalCount(totalCount).setPageCount(pageCount).setList(list).build();
    }

    public static class Builder extends Result.Builder<Result, Builder> {

        private Integer totalCount;
        private Integer pageCount;
        private List<?> list;

        @Override
        protected Builder getThis() {
            return this;
        }

        public Builder setSearch(Search search) {
            this.search = search;
            return this;
        }

        public Builder setTotalCount(Integer totalCount) {
            this.totalCount = totalCount;
            return this;
        }

        public Builder setPageCount(Integer pageCount) {
            this.pageCount = pageCount;
            return this;
        }

        public Builder setList(List<?> list) {
            this.list = list;
            return this;
        }

        @Override
        public ResultList build() {
            Assert.notNull(search, "search 不能为空");
            Assert.notNull(totalCount, "totalCount 不能为空");
            Assert.notNull(pageCount, "pageCount 不能为空");
            Assert.notNull(list, "list 不能为空");
            return new ResultList(search, totalCount, pageCount, list);
        }

    }


}
